<template>
	<image :src="showUrl ||  '/static/image/common/head.svg'" :style="{height: height,width: width}"
		@click="uploadImg"></image>
</template>

<script>
	export default {
		name: "upload-simple",
		props: {
			showUrl: {
				default: null,
			},
			width: {
				default: "80rpx"
			},
			height: {
				default: "80rpx"
			}
		},
		data() {
			return {};
		},
		methods: {
			uploadImg() {
				uni.chooseImage({
					count: 1,
					success: ({
						tempFilePaths
					}) => {
						let url = tempFilePaths[0];
						uni.showLoading({
							title: "上传中"
						})
						this.$api.uploadFile({
							url
						}).then(({
							url,
							fileName
						}) => {
							uni.hideLoading();
							this.$emit("update:showUrl", url);
							this.$emit("getUrl", fileName);
						})
					}
				});
			}
		}
	}
</script>

<style lang="less" scoped>
	image {
		border-radius: 50%;
		display: inherit;
	}
</style>